package com.job.project.schedule;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author 王博
 * @DateTime 2024-07-04 17:16
 */
@Component
public class ScheduleService {
    @Scheduled(cron = "0 */1 * * * ?")
    public void scheduleForOne() throws Exception{
        System.out.println(LocalDateTime.now()+"scheduleForOne:"+Thread.currentThread().getName());
        System.out.println(LocalDateTime.now()+"scheduleForOne:"+Thread.currentThread().getThreadGroup().getName());
        Thread.sleep(5000);
        System.out.println(LocalDateTime.now()+"scheduleForOne:"+Thread.currentThread().getThreadGroup().getName());
    }

    @Scheduled(cron = "0 */1 * * * ?")
    public void scheduleForTwo() {
        System.out.println(LocalDateTime.now()+"scheduleForTwo:"+Thread.currentThread().getName());
        System.out.println(LocalDateTime.now()+"scheduleForTwo:"+Thread.currentThread().getThreadGroup().getName());
    }
}
